<template>
  <div class="login-container"
       :style="{backgroundImage: 'url(' + bgPicture + ')'}">
    <div class="login-content-out">
      <div class="login-content">
        <el-row>
          <el-col :xs="0" :sm="0" :md="12" :lg="12" :xl="12">
            <div class="left-img" :style="{backgroundImage: 'url(' + bgSmallPicture + ')'}"></div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="login-content-main">
              <div class="login-icon-group">
                <div class="login-icon-group-title">
                  <img :src="website.logo == '' ? logoMini : website.logo"/>
                </div>
                <div class="login-icon-group-title">
                  <span class="font-20" style="color: rgb(39 60 143);">{{ website.appName }}</span>
                </div>
              </div>
              <div v-if="!isScan">
                <Account/>
              </div>
              <Scan v-if="isScan"/>
              <div class="switch-action">
                <p>
                  <span v-if="!isScan" @click="switchToScan">扫码登录</span>
                  <span v-else @click="isScan = false">账号登录</span>
                </p>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div class="login-footer">
      <div class="login-footer-content mt15">
        <div class="login-footer-content-warp" style="color: #ffffff" v-html="website.copyright">
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import {toRefs, reactive, computed, defineComponent, onMounted} from 'vue';
import {storeToRefs} from 'pinia';
import {useThemeConfig} from '/@/stores/themeConfig';
import logoMini from '/src/assets/logo-full.svg';
import loginIconTwo from '/@/assets/login-icon-two.svg';
import {NextLoading} from '/@/utils/loading';
import Account from '/@/views/login/component/account.vue';
// import Mobile from '/@/views/login/component/mobile.vue';
import Scan from '/@/views/login/component/scan.vue';
import BgImage from "/@/assets/bg/lg1309095.jpg"
import BgSmallImage from "/@/assets/bg/726693cf83094cf1cb60e2a107880531.jpg"

import {website} from "/@/api/login";
import {Session} from "/@/utils/storage";

// 定义接口来定义对象的类型
interface LoginState {
  tabsActiveName: string;
  isScan: boolean;
  website: WebsiteState,
  bgPicture: any,
  bgSmallPicture: any
}

// 定义接口来定义对象的类型
interface WebsiteState {
  copyright: string,
  version: string,
  logo: string,
  appName: string,
  bgImage: string
  bgImageSmall: string
}

export default defineComponent({
  name: 'loginIndex',
  components: {Account, Scan},
  setup() {
    const storesThemeConfig = useThemeConfig();
    const {themeConfig} = storeToRefs(storesThemeConfig);
    const state = reactive<LoginState>({
      tabsActiveName: 'account',
      isScan: false,
      website: {
        copyright: '',
        logo: '',
        version: '',
        appName: '',
        bgImage: '',
        bgImageSmall: ''
      },
      bgPicture: BgImage,
      bgSmallPicture: BgSmallImage
    });
    // 获取布局配置信息
    const getThemeConfig = computed(() => {
      return themeConfig.value;
    });
    // 页面加载时
    onMounted(() => {
      NextLoading.done();
      getWebsite();
    });
    const getWebsite = () => {
      website({}).then(async (res: any) => {
        const _website = res.data;
        state.website = _website;
        // state.website.bgImage = 'http://img.netbian.com/file/2023/0127/113422oBswH.jpg';
        Session.set('website', _website);
      })
    };
    const switchToScan = () => {
      state.isScan = true
    }
    return {
      logoMini,
      loginIconTwo,
      getThemeConfig,
      switchToScan,
      ...toRefs(state),
    };
  },
});
</script>


<style scoped lang="scss">
.login-container {
  width: 100%;
  height: 100%;
  position: relative;
  background-size: cover;
  background-color: rgba(255, 255, 255, 0.5);

  .login-icon-group {
    width: 100%;
    position: relative;
    margin-bottom: 10px;

    .login-icon-group-title {
      text-align: center;
      display: flex;
      align-items: center;
      height: 60px;
      align-content: space-between;
      flex-wrap: nowrap;
      flex-direction: column;
      justify-content: center;

      img {
        width: 60px;
        /*padding: 20px;*/
        height: 60px;
      }

      &-text {
        padding-left: 5px;
        color: var(--el-color-primary);
      }
    }

    &-icon {
      width: 60%;
      height: 70%;
      position: absolute;
      left: 0;
      bottom: 0;
    }
  }

  .login-content-out {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .login-content {
    width: 900px;
    height: 560px;
    margin: auto;
    background-color: #ffffff;
    overflow: hidden;
    z-index: 1;
    position: relative;
    border-radius: 20px;

    .left-img {
      display: block;
      width: 450px;
      height: 560px;
      background-color: rgba(41, 53, 80, 1);
      background-repeat: no-repeat;
      background-position: center;
      background-size: cover;
    }

    .login-content-main {
      margin: 0 auto;
      width: 100%;
      padding: 30px;

      .login-content-title {
        color: rgb(39 60 143);
        font-weight: 500;
        font-size: 22px;
        text-align: center;
        letter-spacing: 4px;
        margin: 15px 0 30px;
        white-space: nowrap;
        z-index: 5;
        position: relative;
        transition: all 0.3s ease;
      }

      .switch-action {
        text-align: center;
        padding: 10px;
        color: #ffffff;
        cursor: pointer;
      }
    }

    .login-content-main-sacn {
      position: absolute;
      top: 0;
      right: 0;
      width: 50px;
      height: 50px;
      overflow: hidden;
      cursor: pointer;
      transition: all ease 0.3s;
      color: var(--el-text-color-primary);

      &-delta {
        position: absolute;
        width: 35px;
        height: 70px;
        z-index: 2;
        top: 2px;
        right: 21px;
        background: var(--el-color-white);
        transform: rotate(-45deg);
      }

      &:hover {
        opacity: 1;
        transition: all ease 0.3s;
        color: var(--el-color-primary) !important;
      }

      i {
        width: 47px;
        height: 50px;
        display: inline-block;
        font-size: 48px;
        position: absolute;
        right: 2px;
        top: -1px;
      }
    }
  }

  .login-footer {
    position: absolute;
    bottom: 5px;
    width: 100%;

    &-content {
      width: 100%;
      display: flex;

      &-warp {
        margin: auto;
        color: #e0e3e9;
        text-align: center;
        animation: error-num 1s ease-in-out;
        a{
          color: #e0e3e9 !important;
        }
      }
    }
  }
}
</style>
